package light.head.controller.mobile;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import light.head.constant.Parm;
import light.head.constant.Url;
import light.head.dao.mobile.MobileAlbumDAO;
import light.head.dao.mobile.MobilePhotoDAO;
import light.head.dao.sys.OrganDAO;
import light.head.framework.base.SupporterController;
import light.head.model.Album;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping(Url.MOBILE_PHOTOSHOW)
public class MobilePhotoShowController extends SupporterController {
	
	private OrganDAO organDAO;
	private MobileAlbumDAO maDAO;
	private MobilePhotoDAO mpDAO;

	@RequestMapping(Url.INIT)
	public ModelAndView init(HttpServletRequest request, HttpServletResponse response) {
		
		// 获取当前机构的根机构及其所有子机构
		List<Integer> ocs = organDAO.getSonCodeList(organDAO.getRoot(cu_organCode(request)).getCode());
		List<Album> albumList = maDAO.findByOcs(ocs);
		for (Album a : albumList) {
			a.setPhotoList(mpDAO.findByAlc(a.getCode()));
		}
		request.setAttribute(Parm.INFO, albumList);
		return new ModelAndView(Url.MOBILE_PHOTOSHOW_INIT);
	}

	
	@Autowired
	public void setOrganDAO(OrganDAO organDAO) {
		this.organDAO = organDAO;
	}

	@Autowired
	public void setMaDAO(MobileAlbumDAO maDAO) {
		this.maDAO = maDAO;
	}

	@Autowired
	public void setMpDAO(MobilePhotoDAO mpDAO) {
		this.mpDAO = mpDAO;
	}
	
	
	
	
}
